home *** CD-ROM | disk | FTP | other *** search
/ Leonardo the Inventor / Leonardo The Inventor (93026)(Broderbund)(Riverdeep)(2004).iso / LEOWINMV / DATABASE.DIR / 00090_Script_Activate-Enable-Disable Buttons < prev    next >
Text File  |  1996-03-28  |  5KB  |  166 lines

  1. -- ---------------------------------------------------------------
  2. -- Handler setTopicButtons sets the casts of the database buttons
  3. -- to the appropriate casts for the clicked topic (0 = disabled,
  4. -- 1 = enabled) and sets the cursor to a finger if enabled.
  5.  
  6. on setTopicButtons
  7.   global clickedTopic, buttonStates, defaultButtonStates
  8.   global textButton, pictureButton, textState, pictureState
  9.   
  10.   -- default buttonInfo:
  11.   set buttonInfo = clickedTopic & ":" & defaultButtonStates
  12.   set the itemDelimiter = ":"
  13.   
  14.   set buttonInfoLine = binSearchFirstItemInLine(buttonStates, clickedTopic, ":")
  15.   
  16.   if (ButtonInfoLine > 0) then
  17.     set buttonInfo = line ButtonInfoLine of buttonStates
  18.   end if
  19.   
  20.   set textState = value(word 2 of item 2 of buttonInfo)
  21.   set pictureState = value(word 2 of item 3 of buttonInfo)
  22.   
  23.   set the itemDelimiter = ","
  24.   
  25.   setButtonState(textState,textButton)
  26.   setButtonState(pictureState,pictureButton)
  27.   
  28.   setButtonCursor(textState,textButton)
  29.   setButtonCursor(pictureState,pictureButton)
  30. end
  31.  
  32. -- ---------------------------------------------------------------
  33. -- Handler setButtonState calls the appropriate handler to set the
  34. -- cast of the given button.
  35.  
  36. on setButtonState buttonState, buttonSprite
  37.   if (buttonState) then
  38.     enableButton(buttonSprite)
  39.   else 
  40.     disableButton(buttonSprite)
  41.   end if
  42. end
  43.  
  44. -- ---------------------------------------------------------------
  45. -- Handler setButtonCursor sets the cursor of the given buttonSprite
  46. -- to a finger if the button's state is enabled and to the default
  47. -- arrow otherwise.
  48.  
  49. on setButtonCursor buttonState, buttonSprite
  50.   global fingerCursor
  51.   
  52.   if buttonState then
  53.     set the cursor of sprite buttonSprite = fingerCursor
  54.   else
  55.     set the cursor of sprite buttonSprite = -1
  56.   end if
  57. end
  58.  
  59. -- --------------------------------------------------------
  60. -- Handler enableButton makes the given button enabled
  61. -- by changing its cast to its enabled cast.
  62.  
  63. on enableButton whichSprite
  64.   changeButtonCast (whichSprite, "ENABLED")
  65.   setButtonCursor (1, whichSprite)
  66. end
  67.  
  68. -- --------------------------------------------------------
  69. -- Handler disableButton makes the given button disabled
  70. -- by changing its cast to its disabled cast.
  71.  
  72. on disableButton whichSprite
  73.   changeButtonCast (whichSprite, "DISABLED")
  74.   setButtonCursor (0, whichSprite)
  75. end
  76.  
  77. -- --------------------------------------------------------
  78. -- Handler activateButtonKeepActivated makes the given button
  79. -- activated by changing its cast to its activated cast.
  80.  
  81. on activateButtonKeepActivated whichSprite
  82.   changeButtonCast (whichSprite, "ACTIVATED")
  83.   setButtonCursor (0, whichSprite)
  84.   updateStage
  85. end
  86.  
  87. -- --------------------------------------------------------
  88. -- Handler activateButtonThenEnable makes the given button activated
  89. -- by changing its cast to its activated cast and then enables the
  90. -- button when the mouse is released.
  91.  
  92. on activateButtonThenEnable whichSprite
  93.   changeButtonCast (whichSprite, "ACTIVATED")
  94.   
  95.   updateStage
  96.   repeat while (not the mouseUp)
  97.     nothing -- to keep it hilited while the mouse is down
  98.   end repeat
  99.   changeButtonCast (whichSprite, "ENABLED")
  100. end
  101.  
  102. -- --------------------------------------------------------
  103. -- Handler changeButtonCast changes the cast of the button
  104. -- in the given sprite according to the given mode.
  105.  
  106. on changeButtonCast whichSprite, mode
  107.   set buttonType = word 1 of the name of cast the castNum of sprite whichSprite
  108.   set newCastName = buttonType && mode
  109.   set the castNum of sprite whichSprite = the number of cast newCastName
  110. end
  111.  
  112. -- --------------------------------------------------------
  113. -- Handler isActivated checks if the button in the given sprite
  114. -- is active.
  115.  
  116. on isActivated whichSprite
  117.   if (word 2 of the name of cast the castNum of sprite whichSprite = "ACTIVATED") then
  118.     return TRUE
  119.   else
  120.     return FALSE
  121.   end if
  122. end
  123.  
  124. -- --------------------------------------------------------
  125. -- Handler isEnabled checks if the button in the given sprite
  126. -- is enabled.
  127.  
  128. on isEnabled whichSprite
  129.   if (word 2 of the name of cast the castNum of sprite whichSprite = "ENABLED") then
  130.     return TRUE
  131.   else
  132.     return FALSE
  133.   end if
  134. end
  135.  
  136. -- --------------------------------------------------------
  137. -- Handler isDisabled checks if the button in the given sprite
  138. -- is disabled.
  139.  
  140. on isDisabled whichSprite
  141.   if (word 2 of the name of cast the castNum of sprite whichSprite = "DISABLED") then
  142.     return TRUE
  143.   else
  144.     return FALSE
  145.   end if
  146. end
  147.  
  148. -- --------------------------------------------------------
  149. -- Handler enableTopicButtons 
  150.  
  151. on enableTopicButtons
  152.   global pictureButton, textButton
  153.   
  154.   enableButton(pictureButton)
  155.   enableButton(textButton)
  156. end
  157.  
  158. -- --------------------------------------------------------
  159. -- Handler disableTopicButtons 
  160.  
  161. on disableTopicButtons
  162.   global textButton, pictureButton
  163.   
  164.   disableButton(textButton)
  165.   disableButton(pictureButton)
  166. end